package com.tianma315.admin.agent.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tianma315.admin.agent.vo.AgentAddressVO;
import com.tianma315.admin.common.base.CoreServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tianma315.admin.agent.dao.AgentAddressDao;
import com.tianma315.admin.agent.domain.AgentAddressDO;
import com.tianma315.admin.agent.service.AgentAddressService;

import java.util.Date;
import java.util.List;

/**
 * 
 * <pre>
 * 经销商地址
 * </pre>
 * <small> 2019-06-11 16:26:39 | Aron</small>
 */
@Service
public class AgentAddressServiceImpl extends CoreServiceImpl<AgentAddressDao, AgentAddressDO> implements AgentAddressService {

    @Autowired
    private AgentAddressDao agentAddressDao;

    @Override
    public Page<AgentAddressVO> agentAddressVOPage(Integer pageNumber, Integer pageSize, AgentAddressVO agentAddressDTO) {
        // 查询列表数据
        Page<AgentAddressVO> page = new Page<>(pageNumber, pageSize);
        List<AgentAddressVO> list = agentAddressDao.getAddressAndAgentList(agentAddressDTO);
        page.setRecords(list);
        return page;
    }

    @Override
    public Boolean updateStatus(Integer id, Integer status) {
        return null;
    }

    @Override
    public Boolean addAgentAddress(AgentAddressDO agentAddressDO) {
        agentAddressDO.setCreateDate(new Date());
        return insert(agentAddressDO);
    }

    @Override
    public AgentAddressDO getAgentAddressByAgentId(Integer agentId) {
        Wrapper<AgentAddressDO> wrapper = new EntityWrapper<>();
        wrapper.eq("agent_id",agentId);
        AgentAddressDO agentAddressDO = selectOne(wrapper);
        return agentAddressDO;
    }
}
